package com.zhou.listener.baselistener;

import android.util.Log;

import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.FileDownloadLargeFileListener;
import com.zhou.listener.library.baselistener.BaseFileDownloadListener;
import com.zhou.listener.library.baselistener.IBaseFileDownloadListener;
import com.zhou.listener.library.listener.IFileDownloaderDownloadListener;

public class DetailFileDownloadListener extends FileDownloadLargeFileListener implements IBaseFileDownloadListener<IFileDownloaderDownloadListener> {
    private BaseListener baseLitener;
    //为了多继承
    private class BaseListener extends BaseFileDownloadListener<IFileDownloaderDownloadListener> {
        public BaseListener(IFileDownloaderDownloadListener fileDownloaderDownloadListener) {
            super(fileDownloaderDownloadListener);
        }
    }

    public DetailFileDownloadListener(IFileDownloaderDownloadListener fileDownloaderDownloadListener) {
        baseLitener = new BaseListener(fileDownloaderDownloadListener);
    }
    @Override
    public void updateFileDownloaderDownloadListener(IFileDownloaderDownloadListener fileDownloaderDownloadListener) {
        baseLitener.updateFileDownloaderDownloadListener(fileDownloaderDownloadListener);
    }

    @Override
    public void deleteFileDownloaderDownloadListener() {
        baseLitener.deleteFileDownloaderDownloadListener();
    }

    @Override
    public IFileDownloaderDownloadListener getFileDownloaderListener() {
        return baseLitener.getFileDownloaderListener();
    }

    @Override
    protected void pending(BaseDownloadTask task, long soFarBytes, long totalBytes) {
        Log.i("---->","onPending");
        if(baseLitener.listener.get()!=null){
            baseLitener.listener.get().onPending();
        }
    }

    @Override
    protected void progress(BaseDownloadTask task, long soFarBytes, long totalBytes) {
        if(baseLitener.listener.get()!=null){
            Log.i("---->","onProgress"+soFarBytes+"/"+totalBytes+"/-"+baseLitener.listener.get().toString());
            baseLitener.listener.get().onProgress(soFarBytes,totalBytes);
        }
    }

    @Override
    protected void paused(BaseDownloadTask task, long soFarBytes, long totalBytes) {
        Log.i("---->","onPause");
        if(baseLitener.listener.get()!=null){
            baseLitener.listener.get().onPause(soFarBytes,totalBytes);
        }
    }

    @Override
    protected void completed(BaseDownloadTask task) {
        Log.i("---->","onCompleted");
        if(baseLitener.listener.get()!=null){
            baseLitener.listener.get().onCompleted();
        }
    }

    @Override
    protected void error(BaseDownloadTask task, Throwable e) {
        Log.i("---->","onError");
        e.printStackTrace();
        if(baseLitener.listener.get()!=null){
            baseLitener.listener.get().onError();
        }
    }

    @Override
    protected void warn(BaseDownloadTask task) {
        Log.i("---->","onError");
        if(baseLitener.listener.get()!=null){
            baseLitener.listener.get().onError();
        }
    }

}
